<template>
    <div id="member">
        <el-col :span="24" class="action-bar">
            <el-select
                style="margin:0 20px "
                v-model="circle"
                filterable
                remote
                :loading="loading"
                placeholder="请输入圈子名"
                @change="getCircle"
                :remote-method="getCommentList"
                size="medium"
                    >
                <div v-if="circleList.length!=0">
                    <el-option
                    v-for="(item) in circleList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id">
                </el-option>
                </div>
            </el-select>
            <el-button type="primary" size="medium" @click="signatureVisible=true">检索</el-button>
        </el-col>
        

        <!-- 列表 -->
        <el-table
            :data="tableData"
            style="width: 100%">
            <el-table-column
                prop="name"
                label="评论"
                width="200"
                :show-overflow-tooltip="true"
                >
                <template slot-scope="scope">
                    <div >
                        <span v-html="scope.row.content"></span>
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                prop="created_at"
                :show-overflow-tooltip="true"
                label="帖子"
                width="200"
                >
                <template slot-scope="scope">
                    <div v-if="scope.row.post_info" @click.stop="toPostDetail(scope.row)">
                        <span style="cursor:pointer;color:#409EFF" v-html="scope.row.post_info.content" v-if="scope.row.post_info.content"></span>
                        <div style="cursor:pointer;color:#409EFF"  v-else>
                            查看内容
                        </div>
                    </div>
                    <div   v-else >
                            该帖子已删除
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                prop="circle_name"
                label="所属圈子"
                width="100"
                >
            </el-table-column>
            <el-table-column
                prop="classify_name"
                label="帖子类型"
                width="100"
                >
            </el-table-column>
            <el-table-column
                prop="nickname"
                label="评论者昵称"
                width="100"
                >
            </el-table-column>
            <el-table-column
                prop="date"
                label="头像"
                width="100">
                <template slot-scope="scope">
                    <div >
                        <img :src="scope.row.photo_url" alt="" style="width:60px;border-radius:50%;height:60px;object-fit:cover">
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="操作" width='143'>
                <template slot-scope="scope">
                    <el-button type='text' @click="deletePost(scope.row.id)">删除</el-button>
                </template>
            </el-table-column>
            
        </el-table>
        <el-col :span="24" class="footer-bar">
			<div class="page-code">
				<el-pagination
					background
					:page-size="16"
					layout="prev, pager, next"
					:total="totalPage"
					@current-change="pageChange"
						>
				</el-pagination>
			</div>
    </el-col>

		<el-dialog title="帖子类型" :visible.sync="signatureVisible" @close="initData">
            <el-form>
                <el-form-item label="帖子类型">
                    <el-input placeholder="帖子类型" v-model="name"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="submit" >提交</el-button>
			</div>
		</el-dialog>
    </div>
</template>
<script>
export default {
    name:'member',
    data() {
        return {
            name:'',
            signatureVisible:false,//编辑弹窗
            circleTypeId:'',//选中的用户id
            tableData: [{}],
            page:1,
            totalPage:0,
            
            circleList:[],
            circle:'',
            loading:false,
        }
    },
    methods: {  
        toPostDetail(item){
            //跳转帖子详情
            this.$bus.$data.postItem=item.post_info;
            this.$router.push({name:'PostDetail'})
        },    
        getCircle(e){
            this.circle=e
        },
        async getCommentList(searchText){
            //获取圈子列表
            this.loading=true;
            let params={
                page:this.page,
                keyword:searchText,
                limit:16,
                
            }
            let res=await this.$api.getCommentList(
                params);
            if(res.data.level=='success'){
               this.circleList=res.data.data
            }
            this.loading=false
        },
        async getCommentList(){
            //获取列表
            let params={
                page:this.page,
                limit:16,
            }
            let res=await this.$api.getCommentList(
                params);
            if(res.data.level=='success'){
                this.tableData=res.data.data;
                this.totalPage=res.data.page_info.total;
            }
        },
        pageChange(e){
			//翻页
			this.page=e;
			this.getCommentList();
        },
        async submit(){
            //新建修改
            let params={
                name:this.name
            }
            let res=await this.$api.adminAddArticleClassify(params);
            if(res.data.level=='success'){
                this.$message({
                    type:'success',
                    message:res.data.message
                })
                this.getCommentList();
            }else{
                this.$message({
                    type:'error',
                    message:res.data.message
                })
                
            }
        },
        async deletePost(id){
            //删除评论
             let judge=null
            try {
              judge=  await this.$confirm('删除该评论?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
                })
            } catch (error) {
                judge='cancel'
            }
            if(judge=='confirm'){
                let res=await this.$api.delComment({id:id})
                if(res.data.level=='success'){
                    this.$message({
                        type:'success',
                        message:res.data.message
                    })
                    this.getCommentList();
                }else{
                    this.$message({
                        type:'error',
                        message:res.data.message
                    })
                    
                }
            }
            console.log(judge)
        },
        initData(){

        }

    },
    mounted() {
        this.getCommentList()
    },
}
</script>
<style lang="scss" scoped>
.screen{
          margin-top: -10px !important;
      }
    .action-bar{
			background-color: #f2f2f2;
			height: 60px;
			margin: 10px 0px;
			box-sizing: border-box;
			display: flex;
			align-items: center;
			padding-left: 20px;
			.action-bar-input{
				width: 250px;
				margin-right: 14px;
      }
      .task-form-text{
				color: #666666;
			}
		}
		.el-table-style{
			width: 100%;
			border: 1px solid #f2f2f2;
		}
		.footer-bar{
			display: flex;
			justify-content: space-between;
			align-items: center;
			background: #f2f2f2;
			padding: 8px;
			margin: 10px 0px;
			box-sizing: border-box;
		}
		.dialog-footer{
			text-align: center;
		}
		.executorList{
			display: flex;
			flex-wrap: wrap;
			div{
				margin:10px;
				border:1px solid #eee;
				border-radius: 5px;
				padding:5px 10px;
			}
		}
</style>